from django.db import models
from django.utils import timezone

# Create your models here.

class Author(models.Model):
    author_name = models.CharField(max_length=100)
    author_country = models.CharField(max_length=100)

    def __str__(self):
        return self.author_name

class ImgSub(models.Model):
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    sub_name = models.CharField(max_length=200)
    created_date = models.DateTimeField(
            default=timezone.now)
    published_date = models.DateTimeField(
            blank=True, null=True)
    sub_id = models.CharField(max_length=10, unique=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.sub_name